<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改天亮云课堂课程管理')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-course-edit" th:object="${tleduCourse}">
            <input name="courseId" th:field="*{courseId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程分类：</label>
                <div class="col-sm-8" th:with="type=${@dict.getType('course_category')}">
                    <label th:each="dict : ${type}" class="check-box">
                        <input name="courseCategory" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}" th:attr="checked=${tleduCourse.courseCategory.contains(dict.dictValue)?true:false}">
                    </label>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程名称：</label>
                <div class="col-sm-8">
                    <input name="courseName" th:field="*{courseName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程标题：</label>
                <div class="col-sm-8">
                    <input name="courseTitle" th:field="*{courseTitle}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程简介：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" th:field="*{courseDesc}">
                    <div class="summernote" id="courseDesc"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程难度：</label>
                <div class="col-sm-8">
                    <select name="courseDegree" class="form-control m-b">
                        <option value="">所有</option>
                    </select>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商品价格：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('course_price')}">
                        <input type="radio" th:id="${'goodsPrice_' + dict.dictCode}" name="goodsPrice" th:value="${dict.dictValue}" th:field="*{goodsPrice}">
                        <label th:for="${'goodsPrice_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">商品原价：</label>
                <div class="col-sm-8">
                    <input name="commodityPrice" th:field="*{commodityPrice}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">折后价：</label>
                <div class="col-sm-8">
                    <input name="afterDiscountPrice" th:field="*{afterDiscountPrice}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">打折描述：</label>
                <div class="col-sm-8">
                    <textarea name="discountDesc" class="form-control">[[*{discountDesc}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程排序：</label>
                <div class="col-sm-8">
                    <input name="courseSort" th:field="*{courseSort}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否轮播：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isShuffl_' + dict.dictCode}" name="isShuffl" th:value="${dict.dictValue}" th:field="*{isShuffl}">
                        <label th:for="${'isShuffl_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否精品推荐：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isRecommend_' + dict.dictCode}" name="isRecommend" th:value="${dict.dictValue}" th:field="*{isRecommend}">
                        <label th:for="${'isRecommend_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否免费：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isFree_' + dict.dictCode}" name="isFree" th:value="${dict.dictValue}" th:field="*{isFree}">
                        <label th:for="${'isFree_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否对外：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isOut_' + dict.dictCode}" name="isOut" th:value="${dict.dictValue}" th:field="*{isOut}">
                        <label th:for="${'isOut_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程封面：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="courseCover" th:field="*{courseCover}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="courseCover" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程轮播图：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="courseShuffl" th:field="*{courseShuffl}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="courseShuffl" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程PC轮播图：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="coursePcShuffl" th:field="*{coursePcShuffl}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="coursePcShuffl" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">是否展示详情：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                        <input type="radio" th:id="${'isShowDetails_' + dict.dictCode}" name="isShowDetails" th:value="${dict.dictValue}" th:field="*{isShowDetails}">
                        <label th:for="${'isShowDetails_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程详情介绍：</label>
                <div class="col-sm-8">
                    <input type="hidden" name="courseDetails" th:field="*{courseDetails}">
                    <div class="file-loading">
                        <input class="form-control file-upload" id="courseDetails" name="file" type="file">
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程播放量：</label>
                <div class="col-sm-8">
                    <input name="coursePlay" th:field="*{coursePlay}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">课程状态：</label>
                <div class="col-sm-8">
                    <select name="courseState" class="form-control m-b" th:with="type=${@dict.getType('online_status')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{courseState}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">课程备注：</label>
                <div class="col-sm-8">
                    <textarea name="courseRemark" class="form-control">[[*{courseRemark}]]</textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "course/course";
        $("#form-course-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-course-edit').serialize());
            }
        }

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });
    </script>
</body>
</html>